Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.0.1 adapter for non-merklized onchain issuer #284

Closed

Conversation

ilya-korotya
Copy link
Contributor

No description provided.

package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
import { getDateFromUnixTimestamp } from '@iden3/js-iden3-core';
import { Options } from '@iden3/js-jsonld-merklization';

const interfaceDetection = '0x01ffc9a7';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's do it as enum, maybe it makes sence to extend existing one and move to common file

see export enum FunctionSignatures

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main idea was not to export this class to the user. The entry point to the onchain issuer should be only one OnchainIssuer class that decides on the type of OnchainIssuer and creates an instance of the required adapter. If we consider this adapter as some kind of hidden functionality, then it makes no sense to put these variables in the public enum

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to enum, but not to common enum: FunctionSignatures

* @param merklizationOptions Optional settings for merklization.
*/
constructor(
url: string,
Copy link
Collaborator

@vmidyllic vmidyllic Nov 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we pass eth config here, so it will be possible to init this storage separately and still connect to contract?

otherwise rename to rpcUrl.
Also leave a possibility to options object
e.g.

new Adapter(address, options: { configs: EthConfigurationConfig[] / rpcUrl : .. , merklizationOptions, issuerDID }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adapter will not be exported to the end user. The user should use the OnchainIssuer class as an entry point to determine which adapter should be used.

src/storage/blockchain/onchain-issuer.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,56 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you put a lot of testdata here.. is it really needed?

Copy link
Collaborator

@vmidyllic vmidyllic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this file is not in abi folder

} from './common';

export declare namespace SmtLib {
export type ProofStruct = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have such struct - StateProof

auxExistence: boolean,
auxIndex: bigint,
auxValue: bigint
] & {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

& StateProof

@@ -0,0 +1,617 @@
/* Autogenerated file. Do not edit manually. */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this autogenerated file in sdk ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest removing all autogenerated files and keeping only the .abi files with functions that are actively used in our services. This will simplify the PR, making it easier to review, and ensure alignment with our standard approach to interacting with Smart Contracts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We need types for the onchain issuer(s) because it is difficult to manage inline structures, arrays with inline structures, etc.
We decided to move the automatically generated code to https://github.com/iden3/contracts-abi/tree/main/onchain-non-merklized-issuer-base/v0/js and reuse it.

@ilya-korotya ilya-korotya force-pushed the feature/onchain-non-merklized-credential-converter branch from 2fe0eb5 to 1b7ed93 Compare November 21, 2024 08:22
schema.$metadata.uris['jsonLdContext']
];
r.context.push(schema.$metadata.uris['jsonLdContext']);
r.expiration = !r.expiration || r.expiration == 0 ? undefined : r.expiration * 1000;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
r.expiration = !r.expiration || r.expiration == 0 ? undefined : r.expiration * 1000;
r.expiration = r.expiration ? r.expiration * 1000 : undefined;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see it's done

];
r.context.push(schema.$metadata.uris['jsonLdContext']);
r.expiration = !r.expiration || r.expiration == 0 ? undefined : r.expiration * 1000;
r.id = r.id ? r.id : `urn:${uuid.v4()}`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
r.id = r.id ? r.id : `urn:${uuid.v4()}`;
r.id = r.id ?? `urn:${uuid.v4()}`;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this on a browser console and there is a result:

const foo = ""; foo ?? console.log(1);
returns: '' - empty string
const foo = ""; foo ? console.log(2) : console.log(1);
returns 1;

I expect with user pass empty string for the id field, we need generate uuid.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case replace ?? to || for example a = ''; b = '1'; a = a || b; // '1'

src/credentials/credential-wallet.ts Show resolved Hide resolved
if (onchainDisplayMethod.id === '' && onchainDisplayMethod._type === '') {
return undefined;
}
switch (onchainDisplayMethod._type) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add default behavior to switch clause

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any changes that you say done that they are really done

package.json Show resolved Hide resolved
merklizationOptions?: Options;
}
) {
const rpcProvider = new ethers.JsonRpcProvider(options.rpcUrl);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now I don't see how it would be possible to use 'did resolver' approach on client with this adapter.
We need to think and implement the fetch of onchain credentials through did resolver too.

if (onchainDisplayMethod.id === '' && onchainDisplayMethod._type === '') {
return undefined;
}
switch (onchainDisplayMethod._type) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any changes that you say done that they are really done

}

private credentialId(id: bigint): string {
return `urn:iden3:onchain:${this._chainId}:${this._contractAddress}:${id}`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is urn:iden3:onchain: agreed somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. I can't find a place where we made a commitment to this format. But Golang lib uses the same format. I think we agreed this format before.

@vmidyllic
Copy link
Collaborator

fix warnings in linter

@ilya-korotya
Copy link
Contributor Author

The github doesn't represent latest commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants